package com.kele.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    private static final String QUEUE_NAME="page_queue_1";

    private static final String EXCHANGE_NAME = "page_exchange_fanout";

    @Bean(EXCHANGE_NAME)
    public Exchange declareExchange(){
        Exchange exchange = ExchangeBuilder.fanoutExchange(EXCHANGE_NAME).durable(true).build();
        return exchange;
    }

    @Bean(QUEUE_NAME)
    public Queue declareQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();

    }

    @Bean
    public Binding declareBinding(@Qualifier(QUEUE_NAME) Queue queue,
                                  @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("anything").noargs();
    }
}
